import request from './request'
// import store from './../store/index';
const http = {
  request(config) {
    return request(config)
  },
  async post(url, data) {
    try {
      const response = await request({
        url,
        method: 'post',
        data
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async postFile(url, data, contentType) {
    try {
      const response = await request({
        url,
        method: 'post',
        data,
        contentType
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async get(url, params) {
    try {
      const response = await request({
        url,
        method: 'get',
        params
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async put(url, data) {
    try {
      const response = await request({
        url,
        method: 'put',
        data
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async delete(url) {
    try {
      const response = await request({
        url,
        method: 'delete'
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async download(url, params) {
    try {
      const response = await request({
        url,
        method: 'get',
        params,
        responseType: 'blob'
      });
      return response;
    } catch (error) {
      return error;
    }
  },
  async downloadPost(url, data) {
    try {
      const response = await request({
        url,
        method: 'post',
        data,
        responseType: 'blob'
      });
      return response;
    } catch (error) {
      return error;
    }
  }
}

export default http
